package cn.elwy.rcp.ui.explorer.project;

import java.util.Map;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

public class CNFProjectBuilder extends IncrementalProjectBuilder {

  public static final String ID = "cn.elwy.rcp.ui.explorer.CNFProjectBuilder";

  private IProject project;

  public CNFProjectBuilder() {
  }

  protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
    switch (kind) {
    case FULL_BUILD:
      processFullBuild(monitor);
      break;
    default:
      IResourceDelta delta = getDelta(project);
      if (delta == null) {
        processFullBuild(monitor);
      } else {
        processIncrementalBuild(delta, monitor);
      }
      break;
    }
    return null;
  }

  protected void processFullBuild(IProgressMonitor monitor) {

  }

  protected void processIncrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {

  }

  @Override
  protected void clean(IProgressMonitor monitor) throws CoreException {
    super.clean(monitor);
    // FILES_OUTPUT_PATH
    IFolder outputFiles = project.getFolder(project.getFullPath());
    outputFiles.refreshLocal(IResource.DEPTH_INFINITE, monitor);
    if (outputFiles.exists()) {
      outputFiles.delete(true, monitor);
    }
  }

  @Override
  protected void startupOnInitialize() {
    super.startupOnInitialize();
    this.project = getProject();
  }

}